<template>
    <view class="content">
        <view class="conip">
			<view class="conip1">
				<view class="txt">联系人</view>
				<input class="txt1" v-model="name" type="text" placeholder="收货人姓名" />
			</view>
			<view class="conip1">
				<view class="txt">性别</view>
				<view class="txt2">
					<view @tap="swidths(0)">
						<image :src="cur==0?'/static/wxicon2.png':'/static/wxicon1.png'" mode="widthFix"></image>
						<span>先生</span>
					</view>
					<view @tap="swidths(1)">
						<image :src="cur==1?'/static/wxicon2.png':'/static/wxicon1.png'" mode="widthFix"></image>
						<span>女士</span>
					</view>
				</view>
			</view>
			<view class="conip1">
				<view class="txt">联系电话</view>
				<input class="txt1" v-model="tel" type="number" maxlength="11" placeholder="收货人手机号" />
			</view>
			<view class="conip1"  @tap="show = true">
				<view class="txt">所在地址</view>
				<input class="txt1"  v-model="city" disabled="true" type="text" placeholder="收货人所在地址" />
				<image src="/static/wxicon3.png" mode="widthFix" class="wxicon"></image>
			</view>
			<view class="conip1">
				<view class="txt">详细地址</view>
				<input class="txt1" v-model="address" type="text" placeholder="需要具体到街道、小区、门牌号等" />
			</view>
		</view>
        <view class="conip">
			<textarea class="txt3" v-model="con" placeholder="粘贴收件人姓名、手机号、收货地址信息，可快速识别,注:每个需回车区分。"></textarea>
			<view class="txt5">
				<view class="txt4" @tap="sbbtn">识别填充</view>
			</view>
		</view>
		<view class="mrtxt">
			<view @tap="swidths1">
				<image :src="checks?'/static/wxicon2.png':'/static/wxicon1.png'" mode="widthFix"></image>
				<span>设为默认地址</span>
			</view>
		</view>
		<view class="forbtn">
			<view @tap="addressAdd">保存并使用</view>
			<view v-if="id>0" @tap="remove">删除</view>
		</view>
		<u-select v-model="show" mode="mutil-column-auto" :list="list" @confirm="confirm"></u-select>
    </view>
</template>

<script>
const app = getApp();
export default {
    data() {
        return {
			cur:0,
			name:'',
			tel:'',
			longitude:'',
			latitude:'',
			checks:false,
			con:'',
			addrname:'',
			address:'',
			city:'',
			sid:'',
			areaid:'',
			provinceid:'',
			is_type:'',
			sex:'',
			show:false,
			list:[],
			id:''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        var that = this;
		app.globalData.api.request('Pub/cityarea', {}, 'POST', 'form').then((res) => {
			if (res.code == 0) {
				uni.setStorageSync('citylist', res.data)
				this.list = uni.getStorageSync('citylist')
			}else{
				app.globalData.show(res.msg)
			}
		});
		if(uni.getStorageSync('addrcon')){
			var data = uni.getStorageSync('addrcon');
			this.id = data.id
			this.address = data.address;
			this.city = data.city;
			this.sid = data.sid;
			this.areaid = data.areaid;
			this.provinceid = data.provinceid;
			this.checks = data.is_type==1?true:false;
			this.name = data.name;
			this.tel = data.tel;
			uni.setNavigationBarTitle({
				title: '修改地址',
				success: () => {
					////console.log('修改标题成功')
				},
				fail: () => {
					////console.log('修改标题失败')
				},
				complete: () => {
					////console.log('修改标题结束')
				},
			})
		}
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
	
	},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
		
		remove(idx){
			var that = this;
			uni.showModal({
		        title: '温馨提示',
		        content: '确定删除？',
		        cancelColor: "#c23038",
		        success(res) {
		            if (res.confirm) {
		               app.globalData.api.request('Address/addressDel', {
		               	id:that.id,
		               }, 'POST', 'form').then((res) => {
		               	if (res.code == 0) {
		               		app.globalData.d('删除成功~')
		               	}else{
		               		app.globalData.show(res.msg)
		               	}
		               });
		            } else if (res.cancel) {
		                ////console.log('用户点击取消')
		            }
		        }
		    })
		},
		confirm(e){
			//console.log(e)
			this.city = e[0].label+"/"+e[1].label+"/"+e[2].label
			this.sid = e[1].value;
			this.areaid = e[2].value;
			this.provinceid = e[0].value;
		},
		sbbtn(){
			if(this.con==''){
				app.globalData.show('请输入内容~')
				return true
			}
			var uidArr = this.con.split(/[(\r\n)\r\n]+/);
			//console.log(uidArr)
			this.name = uidArr[0]
			this.tel = uidArr[1]
			this.addrname = uidArr[2]
			this.address = uidArr[3]
		},
		swidths1(){
			this.checks = !this.checks
		},
		swidths(e){
			this.cur = e
		},
		addressAdd(){
			var that = this;
			if(this.name==''){
				app.globalData.show('请输入联系人~')
				return true
			}
			if(this.tel==''){
				app.globalData.show('请输入联系人手机号~')
				return true
			}
			if(this.city==''){
				app.globalData.show('请选择所在区域~')
				return true
			}
			if(this.address==''){
				app.globalData.show('请输入详情地址~')
				return true
			}
			var url = this.id>0?'Address/addressEdit':'Address/addressAdd'
			app.globalData.api.request(url, {
				address:this.address,
				city:this.city,
				sid:this.sid,
				areaid:this.areaid,
				name:this.name,
				tel:this.tel,
				provinceid:this.provinceid,
				is_type:this.checks?1:0,
				sex:this.cur==0?'先生':'女士',
				id:this.id
			}, 'POST', 'form').then((res) => {
				if (res.code == 0) {
					app.globalData.d(this.id>0?'修改成功~':'添加成功~')
				}else{
					app.globalData.show(res.msg)
				}
			});
		},
		getLocation(){
			uni.chooseLocation({
				success: (res) => {
					////console.log(res);
					this.address = res.address
					this.longitude = res.longitude
					this.latitude = res.latitude
				}
			});
		},
	}
};
</script>
<style>
	.forbtn>view:nth-child(1){
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #000000;
		background: #FADD43;
	}
	.forbtn>view:nth-child(2){
		background: #FFFFFF;
		border: 2rpx solid #D8D8D8;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 500;
		font-size: 28rpx;
		color: #999999;
		line-height: 70rpx !important;
		margin-top: 30rpx;
	}
	.forbtn>view{
		width: 100%;
		height: 74rpx;
		text-align: center;
		line-height: 74rpx;
		border-radius: 50px;
	}
	.forbtn{
		width: 100%;
		height: auto;
		background-color: #EEEFF3;
		position: fixed;
		left:0px;
		bottom: 0px;
		box-sizing: border-box;
		padding: 30rpx 32rpx;
	}
	.mrtxt>view:nth-child(1)>image{
		width: 18px;
		height: 18px;
		margin-right: 5px;
	}
	.mrtxt>view:nth-child(1){
		width: auto;
		height:35px;
		display: inline-flex;
		justify-content: center;
		align-items: center;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 500;
		font-size: 24rpx;
		color: #3D3D3D;
	}
	.mrtxt{
		width: 686rpx;
		height: 35px;
		display: inline-flex;
		align-items: center;
		margin-left: 32rpx;
	}
	.txt5{
		width: 100%;
		height: 94rpx;
	}
	.txt4{
		width: 156rpx;
		height: 54rpx;
		background: #F6F6F6;
		border-radius: 50px;
		float: right;
		text-align: center;
		line-height: 54rpx;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #9A9899;
		margin-top: 20rpx;
	}
	.txt3{
		width: 100%;
		height: 200rpx;
		box-sizing: border-box;
		padding: 20rpx 0px;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #222;
		border-bottom: 1px solid #E2E2E2;
	}
	.wxicon{
		width: 22px;
		height: auto;
		display: table;
		position: absolute;
		top: 50%;
		right: 0px;
		margin-top: -11px;
	}
	.txt2>view>image{
		width: 18px;
		height: 18px;
		margin-right: 4px;
	}
	.txt2>view:nth-child(1){
		margin-right: 30px;
	}
	.txt2>view{
		width: auto;
		height: 100rpx;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		float: left;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #3D3D3D;
	}
	.txt2{
		width: 75%;
		height: 100rpx;
		display: table;
		float: right;
	}
	.txt1{
		width: 75%;
		height: 100rpx;
		display: table;
		float: left;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #222;
	}
	.txt{
		width: 25%;
		height: 100rpx;
		display: table;
		float: left;
		line-height: 100rpx;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 500;
		font-size: 28rpx;
		color: #3D3D3D;
	}
	.conip1{
		width: 100%;
		height: 100rpx;
		display: table;
		border-bottom: 1px solid #E2E2E2;
		position: relative;
	}
	
	.conip>view:last-child{
		border-bottom: none !important;
	}
	.conip{
		width:686rpx;
		height:auto;
		background:#fff;
		border-radius: 10rpx;
		padding:0px 20rpx;
		margin:32rpx;
		box-sizing: border-box;
		margin-bottom: 20rpx;
		
	}
	page{
		background-color: #EEEFF3;
	}
	.content {
		width: 100%;
		height: auto;
		display: table;
	}
</style>
